#ifndef __M_LOG_H__
#define __M_LOG_H__

#include<iostream>
#include<time.h>
//日志: [17:26:23 log.cpp:12] 打开失败
#define DBG_LEVEL 0
#define INF_LEVEL 1
#define ERR_LEVEL 2
#define DEFAULT_LEVEL DBG_LEVEL

//宏必须写在同一行 \换行符
#define LOG(level,format,...){\
    if(level >= DEFAULT_LEVEL){\
    time_t t = time(nullptr);\
    struct tm* ptm = localtime(&t);\
    char time_str[32];\
    strftime(time_str,31,"%H:%M:%S",ptm);\
    printf("[%s][%s,%d]\t" format "\n", time_str, __FILE__, __LINE__,##__VA_ARGS__);\
    }\
}

#define DLOG(format, ...) LOG("DBG", DBG_LEVEL, format, DBG_LEVEL)
#define ILOG(format, ...) LOG("INF", INF_LEVEL, format, DBG_LEVEL)
#define ELOG(format, ...) LOG("ERR", ERR_LEVEL, format, DBG_LEVEL)

#endif

int main()  
{
    LOG(DEFAULT_LEVEL,"hello %s -- %d","world",27);
    return 0;
}